<template>
	<view>
		<liu-indexed-list :dataList="dataList" @click="click"></liu-indexed-list>
		<!-- <uni-popup ref="popup" background-color="#fff">
			<view class="popBox">
				<view class="boxList" @click="callPhone">
					拨打电话
				</view>
				<view class="boxList" @click="toOrder">
					查看完成订单
				</view>
			</view>
		</uni-popup> -->
	</view>
</template>

<script>
	import {
		bookList
	} from "@/api/book/book.js"
	export default {
		data() {
			return {
				dataList: [],
				checkId:'',
				checkPhone:''
			}
		},
		onLoad() {
			this.requestOne()
		},
		//触底加载
		onReachBottom() {
			let that = this
			if (that.dataList.length == that.listnum) {
				uni.showToast({
					title: '没有更多了',
					icon: "none"
				})
			} else {
				that.pageNum = that.pageNum + 1
				that.requestOne()
			}
		},
		methods: {
			//点击列表回调事件
			click(e) {
				// console.log('点击列表回调：', e)
				this.checkId = e.id
				this.checkPhone = e.phone
				this.callPhone()
			},
			callPhone(){
				uni.makePhoneCall({
					phoneNumber:this.checkPhone
				})
				// console.log(this.checkPhone)
			},
			//请求数据
			requestOne() {
				let that = this
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				let datas = {
					keywords:'',
				}
				bookList(datas).then(response => {
					uni.hideLoading()
					console.log('数据', response)
					// that.list = res.data.list
					// that.listnum = response.data.total
					// if (that.dataList.length < response.data.total) {
					// 	let list = that.dataList.concat(response.data.list)
						that.dataList = that.handleData(response.data)
					// }
				})
			},
			//处理数据，只要想要的
			handleData(array){
				const newArray = array.map(item => {
				  return {
				    phone: item.phone,
				    name: item.name,
					id:item.id,
					img:item.avatar
				  };
				});
				return newArray
			},
		}
	}
</script>

<style>
.popBox{
	width: 750rpx;
	height: 160rpx;
}
.boxList{
	width: 750rpx;
	height: 80rpx;
	line-height: 80rpx;
	text-align: center;
	font-size: 30rpx;
	border-bottom: 1px solid rgb(147, 147, 147);
}
</style>